package com.jkhan.demo.ioflow;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName Person
 * @Description
 * @Author hjk
 * @date 2022/11/1 18:43
 * @Version 1.0
 */
public class Person implements Serializable {
    private String name;
    private int age;
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    private Object readResolve() throws ObjectStreamException {
        return new Person("brady", 23);
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Person.txt"));
        ObjectInputStream ios = new ObjectInputStream(new FileInputStream("Person.txt"));
        Person p = new Person("9人", 23);
        oos.writeObject(p);
        HashMap map = (HashMap) ios.readObject();
        System.out.println(map);
    }
}
